<html>
<head><meta charset="utf-8"><title>dataflow · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html">dataflow</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="183454598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183454598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183454598">(Dec 14 2019 at 19:27)</a>:</h4>
<p>Hi <span class="user-mention" data-user-id="118594">@ecstatic-morse</span> I have a question about dataflow.<br>
If I understand normal dataflow correctly, if you have a <code>BOTTOM_VALUE = false</code> and you <code>gen</code> a value, this spreads and marks all following blocks as also being <code>true</code> for that value. Is there a way to set it up so the a block's value is only <code>true</code> if <em>all</em> incoming blocks are <code>true</code> for that value?</p>



<a name="183454772"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183454772" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183454772">(Dec 14 2019 at 19:31)</a>:</h4>
<p>Besides initializing all entry sets to <code>true</code>, <code>BOTTOM_VALUE = true</code> will use intersection instead of union as the <a href="https://github.com/rust-lang/rust/blob/c8ea4ace9213ae045123fdfeb59d1ac887656d31/src/librustc_mir/dataflow/mod.rs#L654-L659" target="_blank" title="https://github.com/rust-lang/rust/blob/c8ea4ace9213ae045123fdfeb59d1ac887656d31/src/librustc_mir/dataflow/mod.rs#L654-L659">default join operator</a>. I believe "gen"-ing bits still sets them to <code>true</code>, regardless of <code>BOTTOM_VALUE</code>.</p>



<a name="183454983"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183454983" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183454983">(Dec 14 2019 at 19:35)</a>:</h4>
<p>Oh... so if I override the <code>start_block_effect</code> to be the opposite of <code>BOTTOM_VALUE</code>, this may just work out</p>



<a name="183455047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183455047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183455047">(Dec 14 2019 at 19:36)</a>:</h4>
<p>hmm no <span aria-label="frown" class="emoji emoji-1f641" role="img" title="frown">:frown:</span></p>



<a name="183455060"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183455060" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183455060">(Dec 14 2019 at 19:36)</a>:</h4>
<p>if you want to the initial value of the block entry sets to be <code>false</code>, <code>BOTTOM_VALUE</code> should be <code>false</code>, and you should override the <code>join</code> operator instead.</p>



<a name="183455146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183455146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183455146">(Dec 14 2019 at 19:38)</a>:</h4>
<p>You could explain the analysis you're trying to do if you want more help.</p>



<a name="183455204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183455204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183455204">(Dec 14 2019 at 19:40)</a>:</h4>
<p>ok, so I have a ZST <code>Idx</code> so every block just has one bit. I set this bit when I encounter a <code>TerminatorKind::Call</code> to a specific function. I want to be able to ask at each location whether the function has been called if we got to this place in the MIR</p>



<a name="183455216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183455216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183455216">(Dec 14 2019 at 19:40)</a>:</h4>
<p>this means <code>if some_cond { specific_function(); /* here it's true */ } /* here it's false */</code></p>



<a name="183455309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183455309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183455309">(Dec 14 2019 at 19:43)</a>:</h4>
<p>It seems like you want <code>BOTTOM_VALUE</code> to be <code>false</code> (function not called before this point) and the <code>join</code> operator to be union (if the function could have been called in one predecessor but not another, it could have been called in this basic block).</p>



<a name="183455365"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183455365" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183455365">(Dec 14 2019 at 19:44)</a>:</h4>
<p>Oh, there's no <code>else</code> in your example. You mean function has <em>definitely</em> been called, not <em>maybe</em> been called?</p>



<a name="183455394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183455394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183455394">(Dec 14 2019 at 19:45)</a>:</h4>
<p>yes</p>



<a name="183455396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183455396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183455396">(Dec 14 2019 at 19:45)</a>:</h4>
<p>that's my problem. <code>maybe</code> is easy I got that working quickly</p>



<a name="183455398"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183455398" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183455398">(Dec 14 2019 at 19:45)</a>:</h4>
<p>but I don't think dataflow supports my use case</p>



<a name="183455405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183455405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183455405">(Dec 14 2019 at 19:45)</a>:</h4>
<p>In that case yeah, <code>BOTTOM_VALUE</code> is <code>false</code> (function not definitely called) and the <code>join</code> operator is intersection (if the function was definitely called in one predecessor but not definitely called in another, it has not definitely been called in this basic block.</p>



<a name="183455903"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183455903" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183455903">(Dec 14 2019 at 19:57)</a>:</h4>
<p>So.. that's what I tried earlier. I reran and dumped all the state changes. What's happening right now is that <code>specific_function(); foo();</code> says that at <code>foo</code> the bit is false. I dumped all joins and what I'm seeing is two intersects: <code>[] &amp; [MyBit]</code> and <code>[] &amp; []</code>. So I'm guessing that the initial state is also joined with the newly set bits?</p>



<a name="183455960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183455960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183455960">(Dec 14 2019 at 19:58)</a>:</h4>
<p>Ugh, sorry. Yes you're right.</p>



<a name="183456133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183456133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183456133">(Dec 14 2019 at 20:02)</a>:</h4>
<p>So, I mean this is fairly easy to write without duplicating too much dataflow (I'm just looking at basic blocks after all), I was just hoping I could make it work with dataflow so I don't have to write the <code>dirty_set</code> logic :D</p>



<a name="183456222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183456222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183456222">(Dec 14 2019 at 20:04)</a>:</h4>
<p>One last try. how about setting <code>BOTTOM_VALUE</code> to <code>true</code> with the same gen/kill semantics (<code>FnDefinitelyCalled</code>), then the START_BLOCK state to <code>false</code> in <code>initalize_start_block</code>.</p>



<a name="183456227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183456227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183456227">(Dec 14 2019 at 20:04)</a>:</h4>
<p>You mentioned this above</p>



<a name="183456336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183456336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183456336">(Dec 14 2019 at 20:07)</a>:</h4>
<p>and indeed this is what <a href="https://github.com/rust-lang/rust/blob/c8ea4ace9213ae045123fdfeb59d1ac887656d31/src/librustc_mir/dataflow/impls/mod.rs#L384" target="_blank" title="https://github.com/rust-lang/rust/blob/c8ea4ace9213ae045123fdfeb59d1ac887656d31/src/librustc_mir/dataflow/impls/mod.rs#L384"><code>DefinitelyInitalizedPlaces</code></a> does, which has similar semantics</p>



<a name="183456739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183456739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183456739">(Dec 14 2019 at 20:17)</a>:</h4>
<p>Hmm... I thought I tried this, but may have screwed up, I'll see what that does tomorrow morning.</p>



<a name="183478540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183478540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183478540">(Dec 15 2019 at 08:14)</a>:</h4>
<p>It works!! Thanks</p>



<a name="183478541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/dataflow/near/183478541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/dataflow.html#183478541">(Dec 15 2019 at 08:14)</a>:</h4>
<p>/me goes write some docs</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>